/******************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
 * or via info@compiere.org or http://www.compiere.org/license.html           *
 *****************************************************************************/
package org.compiere.apps.form;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;

import org.compiere.apps.ConfirmPanel;
import org.compiere.minigrid.MiniTable;
import org.compiere.plaf.CompiereColor;
import org.compiere.swing.CPanel;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;

/**
 *  
 *
 *  @author Duman Zhunissov
 *  @version $Id: VNavigator.java,v 1.0 2013/09/30
 */
public class VNavigator extends Navigator
	implements FormPanel, ActionListener
{
	private CPanel panel = new CPanel();
	/**
	 *	Initialize Panel
	 *  @param WindowNo window
	 *  @param frame parent frame
	 */
	public void init (int WindowNo, FormFrame frame)
	{
		log.info("");
		m_WindowNo = WindowNo;
		m_frame = frame;
		try
		{
			jbInit();
			dynInit();
			
			frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
			frame.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
		}
		catch(Exception e)
		{
			log.log(Level.SEVERE, "", e);
		}
	}	//	init

	/**	FormFrame			*/
	private FormFrame 	m_frame;

	//
	private CPanel mainPanel = 		new CPanel();
//	private CPanel newPanel = 		new CPanel();
	private CPanel accountPanel = 	new CPanel();
	private CPanel accountOKPanel = new CPanel();
	
	private BorderLayout mainLayout = 		new BorderLayout();
	private BorderLayout accountLayout = 	new BorderLayout();
	private GridBagLayout newLayout = 		new GridBagLayout();
	private FlowLayout accountOKLayout = 	new FlowLayout();

	private ConfirmPanel confirmPanel = new ConfirmPanel();
	
	private TitledBorder newBorder;
	private TitledBorder accountBorder;
	private JScrollPane dataPane = new JScrollPane();

	private JTree tree; // наше дерево

	/**
	 *  Static Init
	 *  @throws Exception
	 */
	private void jbInit() throws Exception
	{
		
		
		DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Color", true);
		DefaultMutableTreeNode black = new DefaultMutableTreeNode("Black");
		DefaultMutableTreeNode blue = new DefaultMutableTreeNode("Blue");
		DefaultMutableTreeNode nBlue = new DefaultMutableTreeNode("Navy Blue");
		DefaultMutableTreeNode dBlue = new DefaultMutableTreeNode("Dark Blue");
		DefaultMutableTreeNode green = new DefaultMutableTreeNode("Green");
		DefaultMutableTreeNode white = new DefaultMutableTreeNode("White");
		parent.add(black);
		parent.add(blue);
		blue.add(nBlue);
		blue.add(dBlue);
		parent.add(green );
		parent.add(white);
		JTree tree = new JTree(parent);

		CompiereColor.setBackground(panel);
		newBorder = new TitledBorder("");
		newBorder.setTitle(Msg.getMsg(Env.getCtx(), "ChargeNewAccount"));
		
		accountBorder = new TitledBorder("");
		accountBorder.setTitle(Msg.getMsg(Env.getCtx(), "Object"));

		mainPanel.setLayout(mainLayout);
//		newPanel.setBorder(newBorder);
//		newPanel.setLayout(newLayout);

		accountPanel.setBorder(accountBorder);
		accountPanel.setLayout(accountLayout);
		
		accountOKPanel.setLayout(accountOKLayout);
		accountOKLayout.setAlignment(FlowLayout.RIGHT);
		confirmPanel.addActionListener(this);
		//
		   // добавляем элементы управления в окно
//		mainPanel.add(newPanel, BorderLayout.NORTH);

//		newPanel.add(tree, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
//			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		mainPanel.add(accountPanel, BorderLayout.SOUTH);

		accountPanel.add(accountOKPanel, BorderLayout.SOUTH);
		accountPanel.add(dataPane, BorderLayout.CENTER);
	}   //  jbInit

	/**
	 * 	Dispose
	 */
	public void dispose()
	{
		if (m_frame != null)
			m_frame.dispose();
		m_frame = null;
	}	//	dispose

	/**
	 *	Action Listener
	 *  @param e event
	 */
	public void actionPerformed (ActionEvent e)
	{
		log.info(e.getActionCommand());
		//
		if (e.getActionCommand().equals(ConfirmPanel.A_OK) || m_C_Element_ID == 0)
			dispose();
		//  new Account
//		else if (e.getSource().equals(newButton))
//			createNew();
//		else if (e.getSource().equals(accountButton))
//			createAccount();
	}   //  actionPerformed


	
	/**
	 *  Dynamic Init
	 *  - Get defaults for primary AcctSchema
	 *  - Create Table with Accounts
	 */
	private void dynInit()
	{
//		DefaultTableModel model = new DefaultTableModel(getData(), getColumnNames());
//		dataTable.setModel(model);
	}

}   //  VCharge
